//
//  Tool.h
//  MGameTribe
//
//  Created by 杨敏 on 13-5-30.
//  Copyright (c) 2013年 YangMin. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "ConstantHeader.h"
#import "HDAppDelegate.h"
#import "JSONKit.h"
#import "JSON.h"
#import "HZcgInline.h"
#import "MBProgressHUD.h"
//typedef void (^BlockWithSQLDB)(id itemDiction , FMDatabase *db,id currentMainValue,int idx,WriteType writeType);
@interface Tool : NSObject
{
    float systemVersion;
    BOOL isFourInch;
    BOOL isSimulator;
}

#pragma mark - 系统版本
@property(nonatomic,readonly)float systemVersion;

#pragma mark - 是否是4英寸屏幕
@property(nonatomic,readonly)BOOL isFourInch;

#pragma mark - 是否是模拟器
@property(nonatomic,readonly)BOOL isSimulator;

+ (Tool *)sharedTool ;

#pragma mark - UI Tool

#define SafeRelease(__v) ([__v release], __v = nil);

#pragma mark - Image with (name+surfix) or (name) +(surfix) .also can load from cache
#define ImageWithName(__name__,__format__,__cache__) ([Tool getImageWithName:__name__ imgFormat:__format__ cache:__cache__])

#pragma mark - 复制图片像素区域
#define ResizeImage(__image__,__left__,__right__,__top__,__bottom__) ([Tool resizeImageWithImage:__image__ left:__left__ right:__right__ top:__top__ bottom:__bottom__])

#pragma mark - ios系统版本
#define SystemVersion [[Tool sharedTool] systemVersion]

#pragma mark - 是否是4英寸屏幕，or 3.5英寸屏幕
#define IsFourInch [[Tool sharedTool] isFourInch]

//CGRectSet 改变坐标函数系列：
void CGRectSetCenterX(UIView *view, CGFloat centerX);
void CGRectSetCenterY(UIView *view, CGFloat centerY);
void CGRectSetX(UIView *view, CGFloat x);
void CGRectSetY(UIView *view, CGFloat y);
void CGRectSetWidth(UIView *view, CGFloat width);
void CGRectSetHeight(UIView *view, CGFloat height);
void CGRectSetOrigin(UIView *view, CGPoint origin);
void CGRectSetSize(UIView *view, CGSize size);
void CGRectSetZeroOrigin(UIView *view);
void CGRectSetZeroSize(UIView *view);

#pragma mark - 弹出/消失Loading提示框
void HideHud(UIView *view,int tag,NSString *msg,CGFloat delay);
void SafeShowHudForContainer(UIView *containnerV ,int tag);
void SafeShowHudWithMsgForContainer(UIView *containnerV ,int tag,NSString *msg);
MBProgressHUD* GetTargetHudWithTag(UIView *contannerView,int tag);

#pragma mark - 弹出/消失Loading提示框
void HideHud(UIView *view,int tag,NSString *msg,CGFloat delay);
void SafeShowHudForContainer(UIView *containnerV ,int tag);
void SafeShowHudWithMsgForContainer(UIView *containnerV ,int tag,NSString *msg);
//MBProgressHUD* GetTargetHudWithTag(UIView *contannerView,int tag);

#pragma mark - 对指定视图 启动/停止 缩放动画：
+(void)stopScaling:(UIImageView *)view;
+(void)startScaling:(UIImageView *)view;




+ (UIImage *)CaptureView:(UIView *)view;

#pragma mark - 安全弹出/消失 模态 视图控制器（兼容所有ios版本的）
void SafePresentViewController(UIViewController *presenter,UIViewController *targetController,FunctonBlock completionBlock,BOOL animated);
void SafeDismissViewController(UIViewController *controller,FunctonBlock completionBlock,BOOL animated);


#pragma mark - 便捷释放uiviewcomtroller的view为nil
void ReleaseViewWithController(UIViewController *controller);


#pragma mark - 封装了系统的UIAlertView
+(void) alertViewWithMessage:(NSString *) message;

#pragma mark - 快捷读取项目中的切图
+(UIImage *)getImageWithName:(NSString *)imgName imgFormat:(NSString *)imgFormat cache:(BOOL)cache;

#pragma mark - 复制图片元素
+(UIImage *)resizeImageWithImage:(UIImage *)sourceImg left:(float)left right:(float)right top:(float)top bottom:(float)bottom;

#pragma mark - 十六进制颜色转化UICOLOR
UIColor *ColorWithHexString(NSString *stringToConvert);

//切割圆形视图
void CircleClipView(UIView *view);

#pragma mark - Lable坐标大小适应:
CGSize GetLabelSizeWithText(NSString *text,UIFont *font,CGSize maxSize);
CGSize GetLableSizeWithLabel(UILabel *label,CGSize maxSize);
void FitLableWithSize(CGSize maxSize,UILabel *label);
void FitLableHeightWithLabel(UILabel *label);
void FitLableWidthWithLabel(UILabel *label);


#pragma mark - 填充UIButton
void FillButton(UIButton *button);
#pragma mark - 居中UIButton
void CenterTheButton(UIButton *button);

#pragma mark - 给视图设置圆角
void SetCorner(CGFloat corner,UIView *view);


#pragma mark - DelegateHelper
#pragma mark - 安全便捷的让delegate对象执行selector方法，同时传入一个object
void LetDelegatePerformSelector(id delegate,SEL selector,id object);


#pragma mark - 表情字符相关的编解码
#pragma mark - 返回表情码数组
+ (NSArray *)ios4EmojiArray;
+ (NSArray *)ios5EmojiArray;

#pragma mark - 先replaceEmojiStr解码字符串中的表情，再stringByRemoveLineBreakChar去掉字符串中的换行符
NSString * EmojiStringWithoutBreakLine(NSString *string);

#pragma mark - 给带有表情的字符串编码：
NSString *StringWithEmojiEncoding(NSString *string);
+ (NSString *)emojiStrUnicodeEncoding:(NSString *)Str;
+ (NSString *)emojiStrEncoding:(NSString *)Str;
+ (NSString *)subStringWithUTF8EmojiString:(NSString *) utf8EmojiString;

//remove break line char
+(NSString *)stringByRemoveLineBreakChar:(NSString *)sourceString;

//replace emoji char
//解码带有表情码的字符串
+ (NSString *)replaceEmojiStr:(NSString *)receiveStr;


#pragma mark - get/write custom plist file
#pragma mark - 根据plist文件名读取出字典，若不存在则根据plist文件名创建新文件
+(NSMutableDictionary *)getBasicInfoPlistInPlist:(NSString *)plistName;
#pragma mark - 在pist中存数据 在指定plist文件里set object for key
+(void)setLocolInfo:(id)object forKey:(NSString *)key inPlist:(NSString *)plistName;
#pragma mark - 从plist文件中根据key读object
+(id)getLocolInfoWithKey:(NSString *)key inPlist:(NSString *)plistName;
#pragma mark - 把object替换写入plist文件里
+(void)writeObject:(id)object plistName:(NSString *)plistName;

#pragma mark - get/write NSUserDefault
+(id)getDefaultsObjectWithKey:(NSString *)key;
+(void)setDefaultsObject:(id)object forKey:(NSString *)key;

#pragma mark - LoadDataFromDatabase
#pragma mark - 从SQL数据库文件中在指定表名里根据指定‘键’读取出对应的字典数据
+(NSMutableDictionary *)getDataFromDBWithTargetId:(id)targetId targetKey:(id)targetKey table:(NSString *)table;

#pragma mark - 计算指定SQL表中数据的个数
+(int)getTotalCountFromTable:(NSString *)tableName;

#pragma mark - save database

#pragma mark - 根据要写入的key列表拼接SQL的update语句前缀和完整的insert语句,返回在字典里，UpdatePrefix：update语句前缀  FullInsert：完整insert语句
+(NSMutableDictionary *)getSQLSatatementsWithSQLKeys:(NSArray *)sqlKeys tableName:(NSString *)tableName;

#pragma mark - 存储指定单条数据，需指定当前的FMDatabase,用于在同一循环中存储另外一个表的的数据,需要传入SQL的update前缀(即不包括where……条件部分)，以及insert完整语句
//+(NSMutableDictionary *)saveSQLWithApikeys:(NSArray *)apikeys tablename:(NSString *)tablename mainAPIkey:(NSString *)mainAPIkey mainSQLkey:(NSString *)mainSQLkey updatePrefix:(NSString *)updatePrefix insertString:(NSString *)insertString fmdb:(FMDatabase *)db itemDiction:(NSDictionary *)itemDiction mainValue:(NSString *)mainServerValue writeType:(WriteType *)writeType;
//
//#pragma mark - 根据targetKeys和targetObjects匹配到之后存储新的objects,但需要传入FMDatabase
//+(void)saveSQLwithSQLKeys:(NSArray *)sqlKeys objects:(NSArray *)objects tableName:(NSString *)tableName targetKeys:(NSArray *)targetKeys targetObjects:(NSArray *)targetObjects db:(FMDatabase *)db;
//#pragma mark - 根据targetKeys和targetObjects匹配到之后存储新的objects,不需要传入FMDatabase
//+(void)saveSQLwithSQLKeys:(NSArray *)sqlKeys objects:(NSArray *)objects tableName:(NSString *)tableName targetKeys:(NSArray *)targetKeys targetObjects:(NSArray *)targetObjects;
//
//#pragma mark - 传入需要存储的数据列表，数据的key列表、数据的主key，SQL表中的key列表、表名、SQL主键 以及在循环存储过程中的回调block函数块
//+(void)saveSQLWithDictionList:(NSArray *)dictionList apiKeys:(NSArray *)apiKeys sqlKeys:(NSArray *)sqlKeys tableName:(NSString *)tableName mainApikey:(NSString *)mainApiKey mainSQLKey:(NSString *)mainSQLKey cacheControlBlock:(BlockWithSQLDB)cacheControlBlock;
//
//#pragma mark - //传入需要存储的数据列表，数据的key列表、数据的主key，SQL表中的key列表、表名、SQL主键 以及在循环存储过程中的回调block函数块
//#pragma mark - 还要传入排序Key和排序起点，需要json编码后存储的key列表
//+(void)saveSQLWithDictionList:(NSArray *)dictionList apiKeys:(NSArray *)apiKeys sqlKeys:(NSArray *)sqlKeys tableName:(NSString *)tableName mainApikey:(NSString *)mainApiKey mainSQLKey:(NSString *)mainSQLKey rowKey:(NSString *)rowKey startRow:(int)startRow jsonKeys:(NSArray *)jsonKeys cacheControlBlock:(BlockWithSQLDB)cacheControlBlock;
//
//#pragma mark - 存储字典数组，需要传入SQL的update前缀(即不包括where……条件部分)，以及insert完整语句,传入的josnkeys是需要特殊处理成json字符串后才存到数据库的,每次循环都有一个状态回调block
//+(void)saveSQLWithDictionList:(NSArray *)dictionList apiKeys:(NSArray *)apiKeys tableName:(NSString *)tableName updateString:(NSString *)updatePrefixString insertString:(NSString *)insertString mainApikey:(NSString *)mainApiKey mainSQLKey:(NSString *)mainSQLKey cacheControlBlock:(BlockWithSQLDB)cacheControlBlock;
//+(void)saveSQLWithDictionList:(NSArray *)dictionList apiKeys:(NSArray *)apiKeys tableName:(NSString *)tableName updateString:(NSString *)updatePrefixString insertString:(NSString *)insertString mainApikey:(NSString *)mainApiKey mainSQLKey:(NSString *)mainSQLKey rowKey:(NSString *)rowKey startRow:(int)startRow jsonKeys:(NSArray *)jsonKeys cacheControlBlock:(BlockWithSQLDB)cacheControlBlock;
//
//
//#pragma mark - 存储字典数组并更新临时缓存
//+(void)saveSQLWithDictionList:(NSArray *)dictionList apiKeys:(NSArray *)apiKeys sqlKeys:(NSArray *)sqlKeys mainAPIKey:(id)mainAPIKey mainSQLKey:(id)mainSQLKey specialKey:(id)specialKey specialValue:(id)specialValue tableName:(NSString *)tableName keyCacheArray:(NSMutableArray *)keyCacheArray cacheKey:(NSString *)cacheKey cacheData:(id)cacheData loadType:(LoadType)loadtype;

#pragma mark - 删除数据库中指定数据:
+(void)deleteSQLDataWithTableName:(NSString *)tableName;
+(void)deleteSQLDataWithTableName:(NSString *)tableName targetKey:(id)targetKey targetObject:(id)targetObject;
+(void)deleteSQLDatasWithTableName:(NSString *)tableName targetKeys:(id)targetKeys targetObjects:(id)targetObjects;

#pragma mark - Data Checker & Transfer
#pragma mark - 检查是否注册推送成功
+(BOOL)checkPushCenterAvailable;
//#define SystemVersion [[[UIDevice currentDevice] systemVersion] doubleValue]

#pragma mark - 将byte转化到MB
+(float)convertbyte:(int)byte isMb:(BOOL)isMb;

#pragma mark - 解析Json字符串
id JsonStringToObjectWithString(NSString *responseString);

#pragma mark - 检查是否有http://开头 ,并返回新的str
+(NSString *)getSafeUrlStrWithStr:(NSString *)urlStr;

#pragma mark - 发布日期格式化：XX时间前
+ (NSString *)calculatepastTime:(NSTimeInterval)pubTime;
#pragma mark - 日期格式化：xx（年）.xx（月）.xx（日）
+ (NSString *)messageTimeFormat:(NSTimeInterval)pubTime;
#pragma mark - 日期格式化：YYYY.MM.dd.HH:mm
+ (NSString *)messageTimeAndDayFormat:(NSTimeInterval)pubTime;

#pragma mark - 检查是否纯整型数字字符
+ (BOOL)isPureInt:(NSString *)string ;

#pragma mark - 去掉系统通知栏上的通知
+(void)clearNotificationCenter;




@end
